package com.pattern.command;

import junit.framework.Assert;

import org.junit.Test;

import com.pattern.command.undocalc.UndoCalc;

public class UndoCalcTest {
	@Test
	public void testInit() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1");
		Assert.assertEquals("1", ret);
	}

	@Test
	public void testAddCmd1() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "+", "2", "<", "+", "1", "<", "+", "3");
		Assert.assertEquals("4", ret);
	}

	@Test
	public void testAddCmd2() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "+", "2", "+", "1", "<", "+", "3");
		Assert.assertEquals("6", ret);
	}

	@Test
	public void testAddCmd3() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "+", "2", "+", "1", "+", "3");
		Assert.assertEquals("7", ret);
	}

	@Test
	public void testAddCmd4() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "+", "2", "+", "1", "+", "3", "<", "<");
		Assert.assertEquals("3", ret);
	}

	@Test
	public void testSubCmd1() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "-", "2", "<", "-", "1", "<", "-", "3");
		Assert.assertEquals("-2", ret);
	}

	@Test
	public void testSubCmd2() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "-", "2", "-", "1", "<", "-", "3");
		Assert.assertEquals("-4", ret);
	}

	@Test
	public void testAddSubCmd() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("1", "+", "2", "-", "1", "<", "-", "3");
		Assert.assertEquals("0", ret);
	}

	@Test
	public void testMulCmd() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("2", "*", "2", "<", "*", "3", "<", "*", "6");
		Assert.assertEquals("12", ret);
	}

	@Test
	public void testDevCmd() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("100", "/", "2", "<", "/", "5", "<", "/", "4");
		Assert.assertEquals("25", ret);
	}

	@Test
	public void testAllCmd() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("100", "/", "2", "<", "+", "5", "<", "*", "4",
				"+", "1", "-", "10", "<", "<");
		Assert.assertEquals("400", ret);
	}

	@Test
	public void testExceptionCmd() {
		UndoCalc calc = new UndoCalc();
		String ret = calc.calc("100", "<", "<");
		Assert.assertEquals("ERROR INPUT", ret);
	}

}
